package com.example.findmystuff;

import com.database.findmystuff.Item;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Calendar;

public class AddFoundItemActivity extends Activity {
	
	Button foundSubmit, foundCancel; //these are buttons
	EditText foundName, foundCategory, foundDescription, foundLocation, foundContact; //these are text boxes
	Toast toast; //this is toast...but seriously, Its a toast message
	Calendar calendar = Calendar.getInstance();
	/**
	 * This method is called when the activity is created
	 * @param savedInstanceState a bundle used to save the state that this instance of the activity is in.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_lost_item);
		
		
		//Variables for buttons
		foundSubmit = (Button) findViewById(R.id.submitButton);
        foundCancel = (Button) findViewById(R.id.cancelButton);
        
        //Variables for text fields
        foundName = (EditText) findViewById(R.id.nameText);
        foundCategory = (EditText) findViewById(R.id.losttypeText);
        foundDescription = (EditText) findViewById(R.id.lostdescriptionText);
        foundLocation = (EditText) findViewById(R.id.lostlocationText);
        foundContact = (EditText) findViewById(R.id.lostcontactText);
        
        
        foundSubmit.setOnClickListener(
        		new View.OnClickListener() {
        			@Override
					public void onClick(View v) {
        				Log.v("loginAttempt", "loggedUser: "+MainActivity.loggedUser); 
        				Item item = new Item(foundName.getText().toString(),foundCategory.getText().toString(), foundDescription.getText().toString(),foundLocation.getText().toString() , foundContact.getText().toString(), "Found", calendar.getTime().toString());
        				
        				MainActivity.database.createItem(MainActivity.database.getUser(MainActivity.loggedUser), item);
						toast = Toast.makeText(getApplicationContext(), "Success, " + foundDescription.getText().toString() + " added", Toast.LENGTH_SHORT);
						toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 70);
						toast.show();
						MainActivity.database.saveObject(MainActivity.database);
        				Intent i = new Intent(AddFoundItemActivity.this, ListItemsActivity.class);
						startActivity(i);
        			}
        		});
        
        foundCancel.setOnClickListener(
        		new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent i = new Intent(AddFoundItemActivity.this, ListItemsActivity.class);
						startActivity(i);
					}
				});
	}

/**
 * Initializes the contents of the Activity's standard options menu.
 * @param menu the standard options menu
 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_add_found_item, menu);
		return true;
	}

}
